package core

import (
	"net/http"
	"html/template"
	"log"
	"encoding/json"
)

var DefaultRender *_DefaultRender = &_DefaultRender{

}

type _DefaultRender struct {
	/*
	默认渲染器
	 */
}

func (this *_DefaultRender) Render(response *HttpResponse, w http.ResponseWriter) {
	switch response.Flag {
	case JSON:
		w.Header().Set("Content-Type", "application/json")
		json.NewEncoder(w).Encode(response.Data)
	case XML:
		log.Println("unsupport XML render")
	case TEMPLATE:
		t, _ := template.ParseFiles(response.Template)
		t.Execute(w, response.Data)
	default:
		log.Println("unsupport flag")
	}
}
